package com.black.cat.jvm.instructions.stack.dup;

import com.black.cat.jvm.instructions.base.InstructionNoOperands;
import com.black.cat.jvm.rtda.Frame;
import com.black.cat.jvm.rtda.OperandStack;
import com.black.cat.jvm.rtda.Slot;

/**
 * @Author blackcat
 * @create 2021/8/13 15:16
 * @version: 1.0
 * @description:dup指令复制栈顶的单个变量
 */
public class DUP extends InstructionNoOperands {

    @Override
    public void execute(Frame frame) {
        OperandStack stack = frame.operandStack();
        Slot slot = stack.popSlot();
        stack.pushSlot(slot);
        try {
            stack.pushSlot(slot.clone());
        } catch (CloneNotSupportedException e) {
            e.printStackTrace();
        }
    }

}
